<template>
  <div class="report-select">
    <el-select v-model="currValue" v-bind="$attrs" v-on="$listeners">
      <el-option v-for="item in options" :key="item.value" :value="item.value" :label="item.label"></el-option>
    </el-select>
  </div>
</template>

<script>
export default {
  name: 'report-select',
  cnName: '报表-字典选择器',
  props: {
    value: [String, Number],
    type: String
  },
  data() {
    return {
      currValue: this.value
    }
  },
  computed: {
    options() {
      const dictStr = localStorage.getItem('REPORT_DICT')
      const dictMap = JSON.parse(dictStr)
      const list = dictMap[this.type]
      const options = list.map(o => {
        return {
          label: o.itemName,
          value: !isNaN(o.itemValue) ? Number(o.itemValue) : o.itemValue
        }
      })
      return options
    }
  },
  watch: {
    value(val) {
      this.currValue = val
    },
    currValue() {
      console.info('wwwwwwww', this.currValue)
      this.$emit('input', this.currValue)
    }
  },
  methods: {}
}
</script>

<style lang="scss" scoped>
.report-select {
}
</style>
